/* @(#)GSProviderdelAction.java    V0.1
 *
 * Project: GSdevelop
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   owen         2006-2-27
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.action;

import java.util.ArrayList;
import java.util.HashMap;

import system.LoginContext;

import client.XMLSend;

import com.hitrust.gs.bean.GSProviderBean;
import com.hitrust.gs.business.GSProviderProcessor;
import com.hitrust.gs.form.ManufactureSetForm;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.lib.GSSystemConfigurator;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.service.GSBaseManager;
import com.hitrust.gs.util.exception.GSException;

import framework.core.DateUtil;
import framework.core.SrvContext;

/**
 * 
 */
public class GSProviderDelAction extends GSBaseAction{

    public String execute(GSBaseForm aForm) throws Exception {    
        String aProviderName = aForm.getRequest().getParameter("providerName");
        String aCountryCode = aForm.getRequest().getParameter("countryCode");
        String aProvinceCode = aForm.getRequest().getParameter("provinceCode");
        String aDistrictCode = aForm.getRequest().getParameter("districtCode");
        String aContactid = aForm.getRequest().getParameter("contactid");
        String aContactphone = aForm.getRequest().getParameter("contactphone");
     
        SrvContext context = SrvContext.getContext(aForm.getRequest());
        LoginContext loginInfo = LoginContext.get(context);       
        GSProviderBean tGSProviderBean = new GSProviderBean(); 
        String  message = "已将该供应商设置为无效";
        String status = "2";
        try {          
            tGSProviderBean.setLast_update_user_id(loginInfo.getLoginUserId());
            tGSProviderBean.setLast_update_user(loginInfo.getLoginUserName());
            tGSProviderBean.setLast_update_time(new DateUtil().getFullString());
            if( GSSystemConfigurator.getInstance().getProjectVersionType().equals("SH")){
                status = aForm.getRequest().getParameter("is_status");
                ManufactureSetForm mf=(ManufactureSetForm) aForm;
                String[] tManufactures = mf.temporary_manufacture;
                String type = aForm.getRequest().getParameter("type").trim();
                for(int i=0;i<tManufactures.length;i++){
                    tGSProviderBean.setGs_provider_id(tManufactures[i]);
                    GSProviderProcessor.setIsOkOrNot(tGSProviderBean, type);
                }
                if(type.equals("1")){
                    message = "已将该供应商设置为有效";
                }
            }else{
                String aProviderId = aForm.getRequest().getParameter("ProviderId"); 
                tGSProviderBean.setGs_provider_id(aProviderId);
                GSProviderProcessor.withdrawTask(tGSProviderBean);
               
            }          
        } catch (GSException err) {
            if (err.getCode() != null) {
                HashMap tMap = new HashMap();
                tMap.put("err", err.getMessage());
                aForm.getRequest().setAttribute("_error", tMap);
                aForm.getRequest().setAttribute("message", err.getMessage());
                aForm.getRequest().setAttribute("exception_code", err.getCode());
                aForm.getRequest().setAttribute("requery", "true");
                aForm.getRequest().setAttribute("action", "A400101.do");
                throw err;
            }
        }
        
        //取得所有国家
        ArrayList tList = GSBaseManager.getAllCountry();
        aForm.getRequest().setAttribute("country",tList);
        //取得所有省
        tList = GSBaseManager.getAllProvince();
        aForm.getRequest().setAttribute("province",tList);
        //取得所有地区
        tList = GSBaseManager.getAllDistinct();
        aForm.getRequest().setAttribute("district",tList);
        //取得公司性质
        String[][] tStr= GSBaseManager.getAllCorpProperty();
        aForm.getRequest().setAttribute("corpproperty",tStr);
        aForm.getRequest().setAttribute("requery","true");
        
        aForm.getRequest().setAttribute("providerName",aProviderName);
        aForm.getRequest().setAttribute("countryCode",aCountryCode);
        aForm.getRequest().setAttribute("provinceCode",aProvinceCode);
        aForm.getRequest().setAttribute("districtCode",aDistrictCode);
        aForm.getRequest().setAttribute("contactid",aContactid);
        aForm.getRequest().setAttribute("contactphone",aContactphone);
        aForm.getRequest().setAttribute("message",message);
        if( GSSystemConfigurator.getInstance().getProjectVersionType().equals("SH")){
            aForm.getRequest().setAttribute("status",status);
        }
        //荣爱接口通讯
        // 设置xml参数
        if (XMLSend.getInstance().isToRong()) {
            String actionName = "SubmitProviderDelete";
            String dataName = "Provider";
            // 传输xml to 荣爱
            XMLSend.getInstance().submitProviderDeleteSendXML(actionName, dataName, tGSProviderBean);

        }
        return GSBaseConstants.FORWARD_SUCCESS;
    }

}
